@*
	For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
	Layout = "_Layout";
}
<body class="layui-anim layui-anim-up">
	<form class="layui-form">
		<div class="layui-form-item">
			<label class="layui-form-label">公司名称</label>
			<div class="layui-input-block">
				<input type="text" name="name" lay-verify="required" autocomplete="off" placeholder="请输入公司名称" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">联系人</label>
			<div class="layui-input-block">
				<input type="text" name="Contacts" lay-verify="required" placeholder="请输入联系人" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">电话</label>
			<div class="layui-input-block">
				<input type="text" name="tel" lay-verify="required" placeholder="请输入电话" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">公司地址</label>
			<div class="layui-input-block">
				<input type="text" name="CompanyAddress" lay-verify="required" placeholder="请输入公司地址" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">共享区域</label>
			<div class="layui-input-block">
				<input type="text" name="Area" placeholder="请输入共享区域" class="layui-input">
			</div>
		</div>
	<div class="layui-form-item">
			<label class="layui-form-label">排序码</label>
			<div class="layui-input-block">
				<input type="text" name="sort" lay-verify="required|number" placeholder="请输入排序吗" class="layui-input">
			</div>
		</div>


		<div class="layui-upload">
			<label class="layui-form-label">请上传图标</label>
			<input type="hidden" name="ico" lay-verify="required" id="ImgUrl" value="" />
			<button type="button" class="layui-btn" id="test1">上传图片</button>
			<div class="layui-input-block">
				<img class="layui-upload-img" id="demo1" style="width:150px;height:150px;visibility:hidden;margin:10px 0;">
				<p id="demoText"></p>
			</div>
		</div>

		<div class="layui-upload">
			<label class="layui-form-label">实力展示</label>
			<button type="button" class="layui-btn" id="test2">多图片上传</button>
			<input type="hidden" name="Imgs" lay-verify="required" id="ImgUrls" value="" />
			<blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
				预览图：
				<div class="layui-upload-list" id="demo2"></div>
			</blockquote>
		</div>

		<div class="layui-form-item layui-form-text">
			<label class="layui-form-label">公司介绍</label>
			<div class="layui-input-block">
				<textarea placeholder="请输入内容" name="Present" class="layui-textarea"></textarea>
			</div>
		</div>
		<!--<div class="layui-form-item layui-form-text">
		  <label class="layui-form-label">编辑器</label>
		  <div class="layui-input-block">
			<textarea class="layui-textarea layui-hide" name="content" lay-verify="content" id="LAY_demo_editor"></textarea>
		  </div>
		</div>-->
		<div class="layui-form-item" align="center">
			<button class="layui-btn layui-btn-normal btnEdit" lay-submit="" lay-filter="btnEdit" style="display:none;">操作</button>
		</div>
	</form>
	<script>
        layui.use(['form','layer','upload'], function(){
        $=layui.jquery;
          var form = layui.form
          ,layer = layui.layer;
        var upload=layui.upload;



        //普通图片上传
  var uploadInst = upload.render({
    elem: '#test1'
    ,url: '/Admin/Banner/UploadFilesAjax'
    ,before: function(obj){
      //预读本地文件示例，不支持ie8
      obj.preview(function(index, file, result){

        $('#demo1').attr('src', result); //图片链接（base64）
        $('#demo1').css({ visibility: "visible" })

      });
    }
    ,done: function(res){
      //如果上传失败
      if(res.code > 0){
        return layer.msg('上传失败');
      }else{
        $('#ImgUrl').val(res.data.src);
      }
      //上传成功
    }
    ,error: function(){
      //演示失败状态，并实现重传
      var demoText = $('#demoText');
      demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
      demoText.find('.demo-reload').on('click', function(){
        uploadInst.upload();
      });
    }
  });
			//多图片上传
			upload.render({
				elem: '#test2'
				, url: '/Admin/Banner/UploadFilesAjax'
				, multiple: true
				, before: function (obj) {
					//预读本地文件示例，不支持ie8
					obj.preview(function (index, file, result) {
						$('#demo2').append('<img src="' + result + '" alt="' + file.name + '" class="layui-upload-img" style="width:150;height:80px;" >')
					});
				}
				, done: function (res) {
					if (res.code > 0) {
						return layer.msg('上传失败');
					} else {
						let imgs = $('#ImgUrls').val();
						if (imgs === "") {
							$('#ImgUrls').val(res.data.src);
						} else {
							$('#ImgUrls').val(imgs+","+res.data.src);
						}

					}
				}
			});

                  //监听提交
            form.on('submit(btnEdit)', function(data){

                var obj = data.field;
                console.log(obj);
                if (obj.State="on") {
                    obj.State = true;
                }
                HsCms.AjaxJson("/Admin/Enterprise/Add", "post", obj, function (result) {
                  if (result.state === "ok") {
                      HsCms.CloseFrame();
                      HsCms.ParentLoad("enterprise");
                  }
                  HsCms.ParentMsg(result.msg);
              });

            return false;
          });



       });
	</script>
</body>